var express = require('express');
var app = express();

//config
var config = require('./config')
var FEServerLocation = config.FEServerLocation;
var FEServerPort = config.FEServerPort;

/**
 * welcome
 */
// 没有挂载路径的中间件,每个请求都会执行
app.use(function timeLog(req, res, next) {
    //添加cookie
    res.cookie('MiddleWare', 'NodeJs Express MiddleWare', { expires: new Date(Date.now() + (60 * 60 * 24 * 1)), httpOnly: true });
    res.header('Access-Control-Allow-Origin',FEServerLocation+':'+FEServerPort);
    res.header('Access-Control-Allow-Credentials','true');
    res.header('Access-Control-Allow-Headers','Content-Type,Content-Length, Authorization, Accept,X-Requested-With');
    res.header('Access-Control-Allow-Methods','Access-Control-Allow-Methods');
    console.log('Time: ', Date.now());
    next();
});

app.get('',function (req,res) {
    res.send('webmaster 中间件');
})

/**
 * 解析cookie的中间件
 */
var cookieParser = require('cookie-parser');
app.use(cookieParser());

/**
 * 加载路由中间件模块
 */
/**
 * manager module
 */
var manager = require('./manager/index');
app.use('/manager',manager);

/**
 * user module
 */
var user = require('./user/index');
app.use('/user',user);


app.listen(3000,function () {
    console.log('Hello nodeJs is listening at port 3000');
});